package com.koicarp.university.graudate.common.utils;

import org.apache.commons.io.FilenameUtils;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

/**
 * 上传文件
 */
public class FileUploadUtil {
    public static String uploadFile(MultipartFile file , String dir) throws IOException {
        String fileName = UUID.randomUUID().toString().replaceAll("-", "");
        String ext = FilenameUtils.getExtension(file.getOriginalFilename());
        String fileNames = fileName + "." + ext;
        String filePath = dir + "/" + fileNames;
        file.transferTo(new File(filePath));

        return fileNames;
    }
}
